package itcast.service.impl;

import itcast.dao.BuildmanagerDao;
import itcast.dao.impl.BuildmanagerDaoImpl;
import itcast.domain.Buildmanager;
import itcast.domain.PageBean;
import itcast.service.BuildmanagerService;

import java.util.List;
import java.util.Map;

public class BuildmanagerServiceimpl implements BuildmanagerService {
    //声明BuildmanagerDao实现类
    private BuildmanagerDao buildmanagerDao=new BuildmanagerDaoImpl();
    @Override
    public List<Buildmanager> findAll() {
        //调用dao完成查询
        return buildmanagerDao.findAll();//找到数据返回给BuildmanagerServlet
    }

    //实现接口方法
    @Override
    public void addbuildmanager(Buildmanager buildmanager) {
        buildmanagerDao.add(buildmanager);
    }

    //实现接口删除方法

    @Override
    public void deleteBuildmanager(String id) {
        buildmanagerDao.delete(Integer.parseInt(id));
    }
    //实现接口查询方法

    @Override
    public Buildmanager findBuildmanagerById(String id) {
        return buildmanagerDao.findById(Integer.parseInt(id));
    }
    //实现修改接口的方法

    @Override
    public void updateBuildmamager(Buildmanager buildmanager) {
        buildmanagerDao.update(buildmanager);
    }
    //删除批量用户


    @Override
    public void delSelectedUser(String[] ids) {
        if(ids!=null &&  ids.length>0){
            //1.遍历数组
            for(String id :ids){
                //2.调用dao删除
                buildmanagerDao.delete(Integer.parseInt(id));
            }
        }

    }

    //分页查询方法实现
    @Override
    public PageBean<Buildmanager> findBuildmanagerByPage(String _currentPage, String _rows) {
        int currentPage =Integer.parseInt(_currentPage);
        int rows=Integer.parseInt(_rows);
        //1.创建空的PageBean对象
        PageBean<Buildmanager> pb=new PageBean<Buildmanager>();
        //2.设置参数
        pb.setCurrentPage(currentPage);
        pb.setRows(rows);
        //3.调用dao查询总记录数
        int totalCount=buildmanagerDao.findTotalCount();
        pb.setTotalCount(totalCount);
        //4.调用dao查询List集合
        //记录开始记录的索引
        int start=(currentPage-1)*rows;
        List<Buildmanager> list=buildmanagerDao.findByPage(start,rows);
        pb.setList(list);
        //5.计算总页码
        int totalPage=(totalCount % rows)==0 ? (totalCount/rows) : (totalCount/rows)+1;
        pb.setTotalPage(totalPage);
        return pb;
    }


    //条件查询
    @Override
    public List<Buildmanager> findBuildmanagerByDate(Map<String, String[]> condition) {
        return buildmanagerDao.findByDate(condition);
    }
    //楼宇管理员登录

    @Override
    public Buildmanager denglu(String buildmanager_username, String buildmanager_password) {
        return buildmanagerDao.denglu(buildmanager_username,buildmanager_password);
    }


   /* @Override
    public Buildmanager denglu(Buildmanager buildmanager) {
        return buildmanagerDao.buildmanagerdenlu(buildmanager.getBuildmanager_username(),buildmanager.getBuildmanager_password());
    }*/
}



